home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / EOF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  641 b   |  27 lines

  1. /* eof.c --- p 495 */
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. main()
  6. {
  7.     int fhandle, total=0, count;
  8.     unsigned char buffer[80];
  9.             /* Open the file "autoexec.bat." Note the two '\' */
  10.     if ( (fhandle = open("c:\\autoexec.bat", O_RDONLY)) == -1)
  11.     {
  12.         printf("open failed");
  13.         exit(1);
  14.     }
  15.     printf("contents of c:autoexec.bat:\n");
  16.     while ( !eof(fhandle))                     /* Read until EOF */
  17.     {
  18.         if ((count = read(fhandle, buffer, 80)) == -1)
  19.         {
  20.             perror("read error");
  21.             break;   /* exit from while loop */
  22.         }
  23.         total += count;
  24.         write(1, buffer, count);
  25.     }
  26.     printf("=== %d bytes read ===\n", total);
  27. }